package com.iceberg;

import java.util.ArrayList;

public class RandomQueue<E> {
    private ArrayList<E> queue;

    public RandomQueue() {
        this.queue = new ArrayList<E>();
    }

    public void add(E e) {
        queue.add(e);
    }

    public E remove() {
        if (queue.size() == 0){
            throw new IllegalArgumentException("no element to remove");
        }
        int randIndex = (int) (Math.random()*queue.size());
        E e = queue.get(randIndex);
        queue.set(randIndex, queue.get(queue.size() -1));
        queue.remove(queue.size() -1);
        return e;
    }

    public int size() {
        return queue.size();
    }

    public boolean Empty() {
        return queue.isEmpty();
    }

}
